package experiment3;

import java.util.ArrayList;

public class StronglyConnectedComponent {
    public static void main(String[] args) {

        Graph<String> G;
        G = new Graph<>();
        G.initializedWithSize(5);
        G.addVertex("a");
        G.addVertex("b");
        G.addVertex("c");
        G.addVertex("d");
        G.addVertex("e");

        G.addEdge("a", "b");
        G.addEdge("c", "a");
        G.addEdge("b", "c");
        G.addEdge("b", "d");
        G.addEdge("c", "d");
        G.addEdge("d", "e");

        ArrayList<String> vtxsList = new ArrayList<>();
        ArrayList<String> dfsVtxs = new ArrayList<>();
        G.dfs(0, vtxsList, dfsVtxs);
        System.out.println("dfs函数递归结果如下: " + vtxsList);
        System.out.println("dfs函数遍历顺序如下: " + dfsVtxs);

        G.resetVisitedArray();
        vtxsList.clear();
        ArrayList<String> entStack = new ArrayList<>();
        ArrayList<String> outStack = new ArrayList<>();

        G.nonRecursiveDFS(0, vtxsList, entStack, outStack);
        System.out.println("dfs非递归结果如下 :" + vtxsList);
        System.out.println("进栈顺序如下 :" + entStack);
        System.out.println("出栈顺序如下 :" + outStack);

        G.resetVisitedArray();
        G.hasCycle();
        ArrayList<String> topLogical = G.topLogical();
        if (topLogical != null) {
            System.out.println("拓扑排序如下 :");
            for (int i = topLogical.size() - 1; i >= 0; i--) {
                System.out.print(topLogical.get(i) + " ");
            }
        }
    }
}